package org.suburban.data;
import com.google.appengine.api.datastore.Entity;

/**
 * 'Station' ORM
 * @author Alexey Palamarchuk (slonnik@gmail.com)
 *
 */
public final class Station{
	
	public final static String TYPE= "Station";
	/** station id 'field'*/
	public final static String ID = "id";
	/** station name 'field'*/
	public final static String NAME = "name";
	/** lower case station name 'field'*/
	public final static String LOWERCASE_NAME = "downcasename";
	/** station comments 'field'*/
	public final static String COMMENTS = "comments";
	
	/** station direction 'field'*/
	public final static String DIRECTION = "direction";
	/** station direction index 'field'*/
	public final static String INDEX = "index";
	
	/** station id*/
	private String id;
	/** station human readable name*/
	private String name;
	/** station comments*/
	private String comments;
	/** direction id*/
	private String directionId;
	/** station index in the direction context*/
	private int index = -1;
	
	
	/**
	 * ctor
	 * @entity entity	- ORM entity
	 */
	Station(Entity entity)
	{
		id = entity.getProperty(ID).toString();
		name = entity.getProperty(NAME).toString();
		directionId = entity.getProperty(DIRECTION).toString();
		comments = entity.getProperty(COMMENTS).toString();
		Object value = entity.getProperty(INDEX);
		index = (value == null) ? -1 : ((Long)value).intValue() ;
	}
	
	/** get station id
	 *@return - station id 
	 */
	public String getId()
	{
		return id;
	}
	
	/**
	 * get station human readable name
	 * @return - station human readable
	 */
	public String getName()
	{
		return name;
	}
	
	/**
	 * get station comments
	 * @return - station comments
	 */
	public String getComments()
	{
		return comments;
	}
	/**
	 * get direction id
	 * @return	- direction id
	 */
	public String getDirectionId()
	{
		return directionId;
	}
	
	/**
	 * get direction index
	 * @return	- direction index
	 */
	public int getIndex()
	{
		return index;
	}
	
	@Override
	public String toString()
	{
		return String.format("id=%1$s name = %2$s dir=%3$s", id, name, directionId);
	}
}
